require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../lib/flexible')
require('../css/index.less')
require('../css/commCss/footer.less')
require('../font/iconfont.css')
    //引入axios
const axios = require('axios')
    //swiper
require('../lib/swiper/swiper-bundle.css')
const Swiper = require('../lib/swiper/swiper-bundle')
    //weui-插件库
require('weui')
const weui = require('weui.js')
require('../css/index.less')
    //导入util
const util = require('../util/util')

document.addEventListener('DOMContentLoaded', function() {

    /* 获取元素 */
    // 排名
    let rankingBottom = document.querySelector('.ranking-bottom')
        // 运动徽章数量
    let b = document.querySelector('.medal-bottom>b')
        // console.log(b);
        // 是否打卡
    const todayPunch = document.querySelector('#todayPunch')
        // 打卡天数
    const punchDay = document.querySelector('#punchDay')
    const R2L = document.querySelector('.R2L') //运动数据模块

    // console.log(punchDay);

    /* util传参底部导航 */
    util.fixBottomNav('index')

    R2L.addEventListener('click', function() {
        location.href = 'exerciseData.html'
    })


    function setSwiper() {
        let mySwiper = new Swiper('.swiper', {
            // direction: 'vertical', // 垂直切换选项
            loop: true, // 循环模式选项
            autoplay: {
                delay: 3000, //延迟时间
                disableOnInteraction: false //是否禁止自动滚动
            },
            // 如果需要分页器
            pagination: {
                el: '.swiper-pagination',
            },

        })
    }
    setSwiper()
        /* *
         *首页渲染数据
         */
    axios.get('http://139.9.177.51:8099/headPageInfo', {
        params: {
            userId: localStorage.getItem('userId')
        }
    }).then(function(res) {
        if (res.data.status === 0) {
            rankingBottom.textContent = res.data.data.rank
            b.textContent = res.data.data.insigniaNum
                //打卡天数等于打卡天数
            punchDay.textContent = res.data.data.punchIn
                // 是否打卡
            res.data.data.isPunch === 'true' ? todayPunch.textContent = '已打卡' : todayPunch.textContent = '今日打卡'
        }
    })

    /* 今日打卡 */
    todayPunch.addEventListener('click', function() {
        axios.get('http://139.9.177.51:8099/clockIn', {
            params: {
                userId: localStorage.getItem('userId')
            }
        }).then(function(res) {
            if (res.data.status === 0) {
                punchDay.textContent++
                    todayPunch.textContent = '已打卡'
                weui.toast('打卡成功', 1000)
            } else {
                weui.toast('今日已打卡', 1000)

            };
        })
    })
})